@echo off
:: Get file extension name.
setlocal EnableDelayedExpansion
set n=0

set tmp="%1"
:LOOP
for /f "delims=., tokens=1,*" %%i in (%tmp%) do (
    set vector[!n!]=%%i
    set /A n+=1

    set tmp="%%j"
    goto LOOP
)

:: Unzip the file.
set tmp1=%1
:LOOP1
set /A n-=1

if "!vector[%n%]!" == "gz" (
    7z -y x %2!tmp1! -o%2
    set tmp1=%tmp1:~0,-3%
    goto LOOP1
)

if "!vector[%n%]!" == "tar" (
    7z -y x %2!tmp1! -o%2
    set tmp1=%tmp1:~0,-3%
    goto LOOP1
)

if !n! == 0 (goto END) else goto LOOP1
:END